package com.example.administrator.bitmaputils;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.io.File;

public class MainActivity extends Activity implements View.OnClickListener {

    private String url = "http://img02.tooopen.com/downs//images/2010/9/16/sy_2010091620583620405.jpg";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.test).setOnClickListener(this);
        findViewById(R.id.clear).setOnClickListener(this);
        ImageView iv = (ImageView) findViewById(R.id.iv);
        findViewById(R.id.images).setOnClickListener(this);
        Picasso.with(this).load(url).into(iv);
        iv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.test:
                test();
                break;
            case R.id.clear:
                clear();
                break;
            case R.id.iv:
                test();
                break;
            case R.id.images:
                Intent intent = new Intent(this, Main2Activity.class);
                startActivity(intent);
                break;

        }
    }

    private void clear() {
        File file = new File(PicturePreviewActivity.getLocalPath(url));
        if (file.exists()) {
            file.delete();
        }
    }

    private void test() {
        Intent intent = new Intent(this, PicturePreviewActivity.class);
        intent.putExtra("url", url);
        // intent.putExtra("smallPath", getSmallPath());
        intent.putExtra("indentify", getIdentify());
        this.startActivity(intent);
    }

    private int getIdentify() {
        return getResources().getIdentifier("test", "drawable",
                getPackageName());
    }

}
